<template>
  <div class="container">
    <el-row :gutter="10" style="margin-bottom: 50px;">
      <el-col :span="6">
        <el-card style="color: #409EFF" class="animate__heartBeat">
          <div><i class="el-icon-user-solid"></i> 用户总数</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">
            36
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #F56C6C" class="animate__heartBeat">
          <div><i class="el-icon-money"></i> 今日销售</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">
            ￥ 35.5
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #67C23A" class="animate__heartBeat">
          <div><i class="el-icon-bank-card"></i> 交易总额</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">
            ￥ 525.5
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #E6A23C" class="animate__heartBeat">
          <div><i class="el-icon-s-shop"></i> 分院数量</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">
            1
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="12">
        <div id="main" style="width: 500px;height: 450px;"></div>
      </el-col>

      <el-col :span="12">
        <div id="pie" style="width: 500px;height: 450px;"></div>
      </el-col>
    </el-row>
    <el-divider></el-divider>
    <el-card style="margin: 10px 0">
      <div style="padding-bottom: 20px;font-size: 24px;color: #409EFF;font-weight: bold">系 统 公 告</div>
      <el-collapse v-model="activeName" accordion v-for="(item,index) in notice">
        <el-collapse-item :name="index + ''">
          <template slot="title">
            <span style="font-size: 20px;font-weight: bold">{{ item.title }}</span><i class="el-icon-warning-outline"></i>
            <span style="margin-left: 20px">{{ item.createTime }}</span>
          </template>
          <div style="padding: 10px 0"><el-image :src="item.img"></el-image></div>
          <!--            <div>{{ item.content }}</div>-->
          <div v-html="item.content"></div>
        </el-collapse-item>
      </el-collapse>
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: "Home",
  data() {
    return {
      activeName: ['0'],
      notice: []
    }
  },
  methods: {
    loadNotice() {
      this.request.get("/notice").then(res => {
        this.notice = res.data.splice(0,5)
      })
    }
  },
  created() {
    this.loadNotice()
  },
  mounted() { //页面元素渲染之后才触发(div出现之后触发)
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    var option;

    option = {
      title: {
        text: '各季度新增人数',
        subtext: '趋势图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      xAxis: {
        type: 'category',
        data: ["第一季度","第二季度","第三季度","第四季度"]
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          name: "",
          data: [],
          type: 'line'
        },
        {
          name: "",
          data: [],
          type: 'bar'
        },
        {
          name: "",
          data: [],
          type: 'bar'
        }
      ]
    };

    //饼状图
    var pieChartDom = document.getElementById('pie');
    var pieMyChart = echarts.init(pieChartDom);
    var pieOption;

    pieOption = {
      title: {
        text: '各季度新增人数',
        subtext: '比例图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          name: '详细信息',
          type: 'pie',
          radius: '50%',
          label: {
            normal: {
              show: true,
              position: "inner",
              textStyle: {
                fontWeight: 300,
                fontSize: 16
              },
              formatter: "{d}%"
            }
          },
          data: [],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };


    this.request.get("/echarts/members").then(res => {
      //对数据赋值
      // option.xAxis.data = res.data.x
      option.series[0].data = res.data
      option.series[1].data = res.data
      option.series[2].data = [5,7,1,9]
      option && myChart.setOption(option);

      //饼状图

      pieOption.series[0].data = [
        { value: res.data[0], name: '第一季度' },
        { value: res.data[1], name: '第二季度' },
        { value: res.data[2], name: '第三季度' },
        { value: res.data[3], name: '第四季度' }
      ]
      pieOption && pieMyChart.setOption(pieOption);
    })

  }
}
</script>

<style scoped>

</style>